<template>
  <div class="wh100" ref="vehicleStatusBarRef"></div>
</template>
<script>
export default {
  data() {
    return {}
  },
  mounted() {
    this.initVehicleStatusBar()
  },
  methods: {
    initVehicleStatusBar() {
      let myChart = this.$echarts.init(this.$refs.vehicleStatusBarRef)
      let option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow', // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        legend: {
          itemWidth: 20,
          itemHeight: 10,
          top: '10%',
          textStyle: {
            color: '#fff',
          },
        },
        xAxis: {
          type: 'value',
          splitLine: {
            show: false,
          },
        },
        yAxis: {
          type: 'category',
          data: ['客运车', '危险品运输车', '网约车', '学生末班车'],
        },
        grid: {
          left: '28%',
          height: '65%',
        },
        color: ['#0034F9', '#F46F8A', '#EFE39B', '#26F3E6'],
        textStyle: {
          color: '#fff',
        },
        series: [
          {
            name: '行驶',
            type: 'bar',
            barWidth: 20,
            stack: '总量',
            label: {
              position: 'insideRight',
            },
            data: [4, 8, 10, 4],
          },
          {
            name: '停车',
            type: 'bar',
            barWidth: 20,
            stack: '总量',
            label: {
              position: 'insideRight',
            },
            data: [10, 5, 4, 10],
          },
          {
            name: '熄火',
            type: 'bar',
            barWidth: 20,
            stack: '总量',
            label: {
              position: 'insideRight',
            },
            data: [4, 8, 10, 4],
          },
          {
            name: '离线',
            type: 'bar',
            barWidth: 20,
            stack: '总量',
            label: {
              position: 'insideRight',
            },
            data: [4, 8, 10, 4],
          },
        ],
      }
      myChart.setOption(option)
    },
  },
}
</script>
<style lang="less" scoped>
.wh100 {
  width: 100%;
  height: 100%;
}
</style>
